package base.keyboard
{
	import utils.ArrayUtil;
	
	/**
	 * 组合键
	 */	
	public class KeyComboCell
	{
		private var _name:String;
		private var _type:String;
		/**
		 *是否激活当前组合键 
		 */		
		private var _isAction:Boolean=true;
		
		/**
		 *组合键值 
		 */		
		private var _keyCodes:Array;
		
		/**
		 *传输的数据(仅用与数据传输过渡) 
		 */
		private var _data:*;
		
		/**
		 * 单项组合键
		 * @param keyCode 键值列表
		 */
		public function KeyComboCell(type:String, name:String, keyCodes:Array, data:*=null)
		{
			_type=type;
			_name=name;
			_keyCodes = keyCodes;
			_keyCodes.fixed = true;
			_data=data;
		}
		
		/**
		 *传输的数据(仅用与数据传输过渡) 
		 * @return 
		 * 
		 */		
		public function get data():*
		{
			return _data;
		}

		/**
		 * 组合键值
		 */		
		public function get keyCodes():Array
		{
			return _keyCodes.concat();
//			return _keyCodes;
		}
		
		/**
		 * 组合键长度
		 */		
		public function get length():uint
		{
			if(_keyCodes==null)return 0;
			return _keyCodes.length;
		}
		
		/**
		 * 检查当前组合键是否包含指定的键值
		 * @param keyCode 键值
		 * @return
		 */
		public function hasKey(keyCode:uint):Boolean
		{
			if(_keyCodes==null)return false;
			return _keyCodes.indexOf(keyCode) > -1;
		}
		
		/**
		 * 指定一个单项组合键与当前组合键比较
		 * @param keyCombo 要进行比较的KeyCombo
		 * @return
		 */		
		public function equals(keyCombo:KeyComboCell):Boolean
		{
			if (keyCombo == this) return true;
			return ArrayUtil.equals(keyCombo.keyCodes, _keyCodes);
		}
		
		/**
		 *资源释放 
		 * 
		 */		
		public function dispose():void
		{
			_keyCodes=null;
			_data=null;
		}

		public function get type():String
		{
			return _type;
		}

		public function set type(value:String):void
		{
			_type = value;
		}

		/**
		 *是否激活当前组合键
		 */
		public function get isAction():Boolean
		{
			return _isAction;
		}

		/**
		 * @private
		 */
		public function set isAction(value:Boolean):void
		{
			_isAction = value;
		}

		public function get name():String
		{
			return _name;
		}

		public function set name(value:String):void
		{
			_name = value;
		}

	}
}